< previous page page_349 next page >

Page 349
    'If you made it this far, then they are valid!
    ValidateEntries = True

End Function
The Click event of the cmdExecute button contains the code that actually performs the calculation and displays the result. To create this event procedure, use the code from Listing 15.4.
Listing 15.4 CALC.ZIPThe Click Event of cmdExecute
Private Sub cmdExecute_Click()
    Dim nVal1 As Integer
    Dim nVal2 As Integer
    Dim nResult As Integer

    If ValidateEntries() = False Then
        RaiseEvent BadEntries
        txtResult = "???"
        Exit Sub
    End If

    nVal1 = Val(txtNum1)
    nVal2 = Val(txtNum2)

    Select Case m_Operation
        Case Add
            nResult = nVal1 + nVal2
        Case Multiply
            nResult = nVal1 * nVal2
        Case Subtract
            nResult = nVal1 - nVal2
        Case Divide
            nResult = nVal1 / nVal2
    End Select

    txtResult = nResult

End Sub
Testing the Control
To see the control from the developer's point of view, close the user control designer. You can create a project group with a Standard EXE test project by selecting File, Add Project. Open the form in the Standard EXE project. Draw an instance of the user control on the form, and display the Properties window. You can set the ButtonCaption, Caption, and Operation properties from this window. Double-click the control, and enter your own code in the BadEntries event:
Private Sub CalcControl1_BadEntries()
    MsgBox "You have entered invalid numbers!"
End Sub
Finally, run the test program, and verify that the calculator fires this event when invalid data is entered.

 
< previous page page_349 next page >